package com.atzzy.ysmall.ysmall_productserviceimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atzzy.ysmall.ysmall_allService.ProductService.CollectionService;
import com.atzzy.ysmall.ysmall_beans.CollectionShop;
import com.atzzy.ysmall.ysmall_common.vo.R;
import com.atzzy.ysmall.ysmall_mapper.CollectionShopMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @Author JAVAZeng
 * @Date 2022/4/12 13:54
 * @Version 1.0
 */
@Service
@Component
public class CollectionServiceImpl implements CollectionService {

    @Resource
    private CollectionShopMapper collectionShopMapper;

    @Override
    public R insertCollection(CollectionShop collectionShop) {
        Date date = new Date();
        collectionShop.setCartTime(date);
        int success = collectionShopMapper.insertTheCollection(collectionShop);
        if(success>0)
        {
            return new R(201,"success",null);
        }else{
            return new R(502,"fail",null);
        }
    }

    @Override
    public R selectCollection(String userId) {
        List<CollectionShop> collectionShops = collectionShopMapper.listTheCollection(userId);
        return new R(201,"success",collectionShops);
    }

    @Override
    public R deleteCollection(int collectionId) {
        int success = collectionShopMapper.deleteCollection(collectionId);
        if(success>0)
        {
            return new R(201,"success",null);
        }else{
            return new R(502,"fail",null);
        }
    }
}
